package cn.cheln.explorer.ui;

import android.content.ContentResolver;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Handler;
import android.view.View;
import android.widget.ListView;
import cn.cheln.explorer.actions.sort.Sort;
import cn.cheln.explorer.beans.FileInfo;
import cn.cheln.explorer.cpnt.adapter.CountAdapter;
import cn.cheln.explorer.cpnt.adapter.CursorItemSrc;
import cn.cheln.explorer.cpnt.adapter.FileAdapter;
import cn.cheln.explorer.cpnt.adapter.SearchAdapter;
import cn.cheln.explorer.ds.MediaArgs;
import cn.cheln.explorer.ds.database.SQLManager;
import cn.cheln.support.data.text.xml.SPUtil;
import cn.cheln.support.ui.adapter.ItemDataSrc;
import cn.cheln.support.unknown.ComparatorRepo;
import com.direction.hold.ui.SearchActivity;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

public class SearchListViewHolder extends ViewHolder
{
  public static String sOrder;
  public static String selectionSearch = SQLManager.SEARCH_FIELD;
  public CursorItemSrc dataSrc;
  public Map<String, ExecBody> exePool = new HashMap();
  SearchActivity fca;
  public boolean inited;
  public boolean modulechanged;
  public String objectWords = "";
  public Map<Integer, String> optionSeq = new TreeMap(ComparatorRepo.intKey);
  public String preobjectWords = null;
  public Map<String, Cursor> typeMap;
  public boolean wordchanged = true;

  public SearchListViewHolder(View paramView, SearchActivity paramSearchActivity)
  {
    super(paramView, paramSearchActivity);
    this.exePool.put("folder", new ExecBody(2131230860, MediaArgs.dirUri, 6));
    this.exePool.put("image", new ExecBody(2131230730, MediaArgs.ImageUri, 1));
    this.exePool.put("audio", new ExecBody(2131230861, MediaArgs.AudioUri, 0));
    this.exePool.put("video", new ExecBody(2131230731, MediaArgs.VideoUri, 2));
    this.exePool.put("apk", new ExecBody(2131230733, MediaArgs.otherUri, 4));
    this.exePool.put("doc", new ExecBody(2131230862, MediaArgs.otherUri, 3));
    this.typeMap = new HashMap();
    this.inited = false;
    this.fca = paramSearchActivity;
    Object localObject = SPUtil.getValue(this.fca, "file", "Key_Search_Sort", String.class);
    if ((localObject == null) || (localObject.toString().equals("")))
    {
      this.fca.setSort();
      return;
    }
    sOrder = localObject.toString();
  }

  public void changedFor2_3()
  {
    changedFor2_3(true);
  }

  public void changedFor2_3(boolean paramBoolean)
  {
    monitorenter;
    while (true)
    {
      int j;
      try
      {
        Cursor localCursor1;
        finish(paramBoolean);
        int i = this.optionSeq.size();
        if (i == 0);
        do
        {
          return;
          sOrder = " order by " + this.fca.policy.getContent().toString();
          String str1 = (String)this.optionSeq.get(new Integer(this.optionSeq.keySet().toArray()[0].toString()));
          this.objectWords = this.objectWords.toLowerCase();
          localCursor1 = getCursor(0, this.objectWords, str1, paramBoolean);
        }
        while (localCursor1 == null);
        this.dataSrc = new CursorItemSrc(this.fca.context, localCursor1, this.fca.datamap, FileInfo.class, null);
        this.fca.adapter.setItemDataSrc(this.dataSrc);
        if (this.optionSeq.size() > 1)
        {
          j = 1;
          if (j < this.optionSeq.size())
            break label257;
        }
        notifyCatNum();
        this.fca.adapter.reinitSelectedAllBck(this.dataSrc.getCount());
        ((SearchAdapter)this.fca.adapter).switchKeyWords(this.objectWords);
      }
      finally
      {
        monitorexit;
      }
      label257: String str2 = (String)this.optionSeq.get(new Integer(this.optionSeq.keySet().toArray()[j].toString()));
      Cursor localCursor2 = getCursor(j, this.objectWords, str2, paramBoolean);
      if (localCursor2 != null)
        this.fca.adapter.getItemDataSrc().swapCursor(localCursor2);
      ++j;
    }
  }

  public void closeCursor(Cursor paramCursor)
  {
    if ((paramCursor == null) || (paramCursor.isClosed()))
      return;
    paramCursor.close();
  }

  public void dataChanged(Object[] paramArrayOfObject)
  {
    monitorenter;
    try
    {
      changedFor2_3(Boolean.parseBoolean(paramArrayOfObject[0].toString()));
      return;
    }
    catch (Exception localException)
    {
    }
    finally
    {
      monitorexit;
    }
  }

  public void finish()
  {
    finish(true);
  }

  public void finish(boolean paramBoolean)
  {
    if (this.dataSrc != null)
      this.dataSrc.clear();
    if (!(paramBoolean))
      return;
    Iterator localIterator = this.exePool.values().iterator();
    while (true)
    {
      if (localIterator.hasNext());
      closeCursor(((ExecBody)localIterator.next()).cursor);
    }
  }

  public Integer getCount(int paramInt, String paramString1, String paramString2)
  {
    Cursor localCursor;
    if (paramString2 == null);
    do
    {
      return null;
      ContentResolver localContentResolver = this.fca.getContentResolver();
      Uri localUri = ((ExecBody)this.exePool.get(paramString2)).uri;
      String[] arrayOfString = new String[1];
      arrayOfString[0] = ((ExecBody)this.exePool.get(paramString2)).getCount(paramString1) + "--";
      localCursor = localContentResolver.query(localUri, arrayOfString, null, null, null);
    }
    while ((localCursor == null) || (localCursor.getCount() != 1));
    localCursor.moveToFirst();
    int i = localCursor.getInt(0);
    localCursor.close();
    ((ExecBody)this.exePool.get(paramString2)).countCache = i;
    return Integer.valueOf(i);
  }

  public Cursor getCursor(int paramInt, String paramString1, String paramString2, boolean paramBoolean)
  {
    if (paramString2 == null)
      return null;
    if ((!(paramBoolean)) && (((((ExecBody)this.exePool.get(paramString2)).moduleOpened == null) || (!(((ExecBody)this.exePool.get(paramString2)).moduleOpened.booleanValue())))))
      return ((ExecBody)this.exePool.get(paramString2)).cursor;
    closeCursor(((ExecBody)this.exePool.get(paramString2)).cursor);
    ExecBody localExecBody = (ExecBody)this.exePool.get(paramString2);
    ContentResolver localContentResolver = this.fca.getContentResolver();
    Uri localUri = ((ExecBody)this.exePool.get(paramString2)).uri;
    String[] arrayOfString = new String[1];
    arrayOfString[0] = ((ExecBody)this.exePool.get(paramString2)).getSql(paramString1) + "--";
    localExecBody.cursor = localContentResolver.query(localUri, arrayOfString, null, null, null);
    ((ExecBody)this.exePool.get(paramString2)).countCache = ((ExecBody)this.exePool.get(paramString2)).cursor.getCount();
    return ((ExecBody)this.exePool.get(paramString2)).cursor;
  }

  public void init()
  {
    if (this.inited)
      return;
    this.fca.initListView(CountAdapter.class);
    this.fca.initBottomBar();
    this.fca.buildAdapter(SearchAdapter.class, this.fca.getAdaptInfo());
    ((SearchAdapter)this.fca.adapter).setHighlightInfo(this.objectWords, new String[] { "name" }, Color.parseColor("#E33539"));
    this.fca.listview.setAdapter(this.fca.adapter);
  }

  public void notifyCatNum()
  {
    new Thread()
    {
      public void run()
      {
        super.run();
        SearchListViewHolder.this.fca.backHandler.sendEmptyMessage(3);
      }
    }
    .start();
  }

  public void rebind()
  {
    monitorenter;
    while (true)
      try
      {
        if ((Cursor)this.fca.adapter.getItemDataSrc().getContent() != null)
        {
          boolean bool = ((Cursor)this.fca.adapter.getItemDataSrc().getContent()).isClosed();
          if (bool)
            return;
        }
        if ((Cursor)this.fca.adapter.getItemDataSrc().getContent() != null)
          ((Cursor)this.fca.adapter.getItemDataSrc().getContent()).requery();
      }
      finally
      {
        monitorexit;
      }
  }

  public void refresh()
  {
  }

  public void start()
  {
    if (this.fca.searchPageView == null)
    {
      SearchActivity localSearchActivity1 = this.fca;
      SearchActivity localSearchActivity2 = this.fca;
      View localView = this.fca.buildList();
      localSearchActivity2.searchPageView = localView;
      localSearchActivity1.setContentView(localView);
    }
    init();
  }

  public static class ExecBody
  {
    public int countCache;
    public Cursor cursor;
    private int iType;
    public Boolean moduleOpened;
    public String strType;
    public Uri uri;
    public int viewid;

    public ExecBody(int paramInt1, Uri paramUri, int paramInt2)
    {
      this.viewid = paramInt1;
      this.uri = paramUri;
      this.iType = paramInt2;
    }

    public String getCount(String paramString)
    {
      String str = getSql(paramString);
      return "count(distinct _data)" + str.substring(str.indexOf("from"));
    }

    public String getSql(String paramString)
    {
      switch (this.iType)
      {
      case 5:
      default:
        return "";
      case 1:
        String str6 = SearchListViewHolder.sOrder;
        Float localFloat = Float.valueOf(-1.0F);
        String[] arrayOfString6 = new String[1];
        arrayOfString6[0] = SearchListViewHolder.selectionSearch;
        return SQLManager.getSearchPart_Image_Sql(paramString, str6, localFloat, arrayOfString6);
      case 0:
        String str5 = SearchListViewHolder.sOrder;
        String[] arrayOfString5 = new String[1];
        arrayOfString5[0] = SearchListViewHolder.selectionSearch;
        return SQLManager.getSearchPart_Music_Sql(paramString, str5, arrayOfString5);
      case 2:
        String str4 = SearchListViewHolder.sOrder;
        String[] arrayOfString4 = new String[1];
        arrayOfString4[0] = SearchListViewHolder.selectionSearch;
        return SQLManager.getSearchPart_Video_Sql(paramString, str4, arrayOfString4);
      case 4:
        String str3 = SearchListViewHolder.sOrder;
        String[] arrayOfString3 = new String[1];
        arrayOfString3[0] = SearchListViewHolder.selectionSearch;
        return SQLManager.getSearchPart_Apk_Sql(paramString, str3, arrayOfString3);
      case 3:
        String str2 = SearchListViewHolder.sOrder;
        String[] arrayOfString2 = new String[1];
        arrayOfString2[0] = SearchListViewHolder.selectionSearch;
        return SQLManager.getSearchPart_Files_Sql(paramString, str2, arrayOfString2);
      case 6:
      }
      String str1 = SearchListViewHolder.sOrder;
      String[] arrayOfString1 = new String[1];
      arrayOfString1[0] = SearchListViewHolder.selectionSearch;
      return SQLManager.getSearchPart_Folder_Sql(paramString, str1, arrayOfString1);
    }
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     cn.cheln.explorer.ui.SearchListViewHolder
 * JD-Core Version:    0.5.2
 */